package com.mach.platform.controller;


import com.mach.platform.domain.MessageParam;
import com.mach.platform.domain.iot.IotDev;
import com.mach.platform.service.IotDevServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;
import java.util.Map;

@Controller
public class WsCtrl {

    @Autowired
    private SimpMessagingTemplate messagingTemplate;

    @Autowired
    private IotDevServiceImpl devService;

    @ResponseBody
    @MessageMapping("/heat")
    public void sends(MessageParam messageParam, Principal principal) {

        Map simpleRealData = devService.simpleRealData(messageParam.getDid());
        messageParam.setResult(simpleRealData);
        messagingTemplate.convertAndSendToUser(principal.getName(), "/realData/uu", messageParam);
    }

    @ResponseBody
    @MessageMapping("/heat2")
    public void sendss(MessageParam messageParam, Principal principal) {

        Map simpleRealData = devService.simpleRealData(messageParam.getDid());
        messageParam.setResult(simpleRealData);
        messagingTemplate.convertAndSendToUser(principal.getName(), "/realData/uuu", messageParam);
    }

}
